package com.crm.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.crm.pojo.User;
import com.crm.service.UserService;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport{

	private static final long serialVersionUID = 1L;
	private User user;
	
	private HttpServletRequest request = ServletActionContext.getRequest();
	private UserService userService; 
	
	
	public String execute() {
		return SUCCESS;
	}
	
	public String login() {
		User u = userService.login(user);
		if(u != null) {
			HttpSession session = request.getSession();
			session.setAttribute("user", u);
			return SUCCESS;
		} else {
			return LOGIN;
		}
	}

	public String toMain() {
		return SUCCESS;
	}
	
	//get set
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	
	
}
